<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	@import "/common/iconfont/iconfont.css";
	/* #ifndef APP-PLUS-NVUE */
	@import "/common/main.css";
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "colorui/animation.css";
	@import './tuniao-ui/index.scss';
	@import './tuniao-ui/iconfont.css';

	/* #endif */
	/* 骨架屏方案 */
	.Skeleton {
		background-color: #f3f3f3;
		padding: 20upx 0;
		border-radius: 6upx;
	}
</style>


<script>
	// 对Date的扩展，将 Date 转化为指定格式的String
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
	// 例子：
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
	Date.prototype.Format = function(fmt) { //author: meizz
		var o = {
			"M+": this.getMonth() + 1, //月份
			"d+": this.getDate(), //日
			"h+": this.getHours(), //小时
			"m+": this.getMinutes(), //分
			"s+": this.getSeconds(), //秒
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度
			"S": this.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
					.length)));
		return fmt;
	}
	import Vue from 'vue'
	const CryptoJS = require("crypto-js");
	export default {
		globalData: {
			type:"h5",
			miniOpenid:"",
			schoolIndex:-1,
			code:"6075",//邀请码
			remark:"",
			openid: -1,
			userinfo: '',
			shuaxinAddressID: '',
			shuaxinmoney: false,//发放薪资
			shuaxin: false,
		},
		onLaunch: function() {
			//字符串加密
			Vue.prototype.$strEncode = function($data) {
					if (typeof $data == 'object') {
						$data = JSON.stringify($data);
					}
					var key = CryptoJS.enc.Latin1.parse('BC1F5E3BAEE198AC');
					var iv = CryptoJS.enc.Latin1.parse('1F5E3BAEE198ACE1');
					var encoded = CryptoJS.AES.encrypt($data, key, {
						iv: iv,
						mode: CryptoJS.mode.CBC, //模式
						adding: CryptoJS.pad.ZeroPadding
					}).toString();
					if (!encoded) {
						return '';
					}
					return encoded
				},
				Vue.prototype.clientType = function() {
					let c = 1; //默认为电脑
					// #ifdef APP-PLUS
					switch (uni.getSystemInfoSync().platform) {
						case 'android':
							c = 3;
							break;
						case 'ios':
							c = 4;
							break;
						default:

					}
					// #endif	

					// #ifdef h5
					c = 2;
					// #endif	

					// #ifdef MP-WEIXIN
					c = 5;
					// #endif
					return c
				}
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})

			//关闭页面
			Vue.prototype.closePage = function() {
				console.log(getCurrentPages());
				if (getCurrentPages().length > 1) {
					uni.navigateBack();
				} else {
					// #ifdef H5
					history.back()
					// #endif
					// #ifndef H5
					uni.reLaunch({
						url: '/pages/index/index'
					});
					// #endif

				}
			}


			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			Vue.prototype.navTo = function(url) {
				// if(!this.hasLogin){
				// 	url = '/pages/user/login/login';
				// }
				uni.navigateTo({
					url: url
				})
			}
		},
		onShow: function() {
			try {
				const value = uni.getStorageSync('userData');
				if (value) {
					//有登录信息
					that.$store.dispatch("setUserData", value); //存入状态

				} else {
					//用户未登录
					/* uni.navigateTo({
						url: '/pages/user/login/login',
					}); */
				}
			} catch (e) {
				// error
			}
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>
